package com.xl.activiti.demo.listener;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.springframework.stereotype.Component;

/**
 * @author zhongwm
 */
@Slf4j
@Component
public class ActivitiGlobalEventListener implements ActivitiEventListener {
    @Override
    public void onEvent(ActivitiEvent activitiEvent) {
        switch (activitiEvent.getType()) {
            case PROCESS_STARTED:
                log.info("开启新流程. executionId:{}, definitionId:{}, instanceId:{}",
                        activitiEvent.getExecutionId(),
                        activitiEvent.getProcessDefinitionId(),
                        activitiEvent.getProcessInstanceId());
                break;
            case PROCESS_COMPLETED:
                log.info("流程结束. executionId:{}, definitionId:{}, instanceId:{}",
                        activitiEvent.getExecutionId(),
                        activitiEvent.getProcessDefinitionId(),
                        activitiEvent.getProcessInstanceId());
                break;
            case TASK_CREATED:
                log.info("开启新任务. executionId:{}, definitionId:{}, instanceId:{}",
                        activitiEvent.getExecutionId(),
                        activitiEvent.getProcessDefinitionId(),
                        activitiEvent.getProcessInstanceId());
                break;
            case TASK_COMPLETED:
                log.info("任务完成. executionId:{}, definitionId:{}, instanceId:{}",
                        activitiEvent.getExecutionId(),
                        activitiEvent.getProcessDefinitionId(),
                        activitiEvent.getProcessInstanceId());
                break;
            case PROCESS_CANCELLED:
                log.info("进程取消，删除实例. executionId:{}, definitionId:{}, instanceId:{}",
                        activitiEvent.getExecutionId(),
                        activitiEvent.getProcessDefinitionId(),
                        activitiEvent.getProcessInstanceId());
                break;
            default:
        }
    }

    @Override
    public boolean isFailOnException() {
        return false;
    }
}
